package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ProductFirst;
import cn.wolfcode.crm.query.JSONResult;
import cn.wolfcode.crm.service.IProductFirstService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("productFirst")
public class ProductFirstController {

    @Autowired
    private IProductFirstService productFirstService;

    //由于dataGrid组件返回必须为json,所以跳转界面就分开
    @RequestMapping("selectAll")
    @ResponseBody
    public List<ProductFirst> selectAll() {
        return productFirstService.selectAll();
    }

    @RequestMapping("view")
    public String view() {
        return "productFirst";
    }

    //页面需要的json数据
    @RequestMapping("query")
    @ResponseBody
    public List<ProductFirst> query() {
        return productFirstService.selectAll();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(ProductFirst productFirst){
        JSONResult result = new JSONResult();
        try{
            productFirstService.saveOrUpdate(productFirst);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            productFirstService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
